import { RequestHandler } from "express";
import multer from "multer";
import path from "path";
import {v4}  from "uuid"
export function getFileUploader(env: string): RequestHandler {
    if (env == "development") {
        let fieldId = v4();
        const storage = multer.diskStorage({
            destination: function (req, file, cb) {
                cb(null, path.resolve("./", "src", "publicRes", "image"))
            },
            filename: function (req, file, cb) {
                cb(null, fieldId+ '-' + path.extname(file.originalname))
            }
        })

        const upload = multer({ storage: storage }).single("file")
        return upload
    }
    else if(env=="production"){
        return {} as RequestHandler;
    }    



    return {} as RequestHandler;
}